<?php

include dirname(dirname(dirname(__FILE__))) . '/include/common.php';

class webServiceUpdateRequestAddressGuest extends core {

    public function process() {
        $guest_id = intval($_POST['guest_id']);
        $event_id = intval($_POST['event_id']);
        if ($guest_id > 0) {
            $guest_id = $this->db->escape($guest_id);
            $data = $this->db->get_row("SELECT * FROM guest_event WHERE guest_id=$guest_id AND event_id='$event_id'");
            if ($data) {
                $address = $this->db->escape(strip_tags(trim($_POST['address'])));
                $city = $this->db->escape(strip_tags(trim($_POST['city'])));
                $state = $this->db->escape(strip_tags(trim($_POST['state'])));
                $zipcode = $this->db->escape(strip_tags(trim($_POST['zipcode'])));
                $query ="UPDATE `guests` SET `address`='$address',
                        `city`='$city',`state`='$state',`zipcode`='$zipcode' 
                            WHERE `guest_id`= '$guest_id'";
                
                if ($this->db->query($query)===false) {
                   
                    $this->_JSONResponse(array('error' => 1, 'msg' => 'Oops, something went wrong. Please try again'));
                } else {
                     $this->db->query("UPDATE guest_event SET is_requested_address=1 WHERE guest_id='$guest_id' AND event_id='$event_id'");
                    $this->_JSONResponse(array('error' => 0, 'msg' => 'Your address has been updated'));
                }
            } else {
                $this->_JSONResponse(array('error' => 1, 'msg' => 'Guest does not exist'));
            }
        } else {
           $this->_JSONResponse(array('error' => 1, 'msg' => 'Guest does not exist'));
        }
    }

}

$processor = new webServiceUpdateRequestAddressGuest();
$processor->process();
?>